<extend name="Public/base" />
<!-- 界面样式 -->
<block name="style">
    <style>
        .logo_img {
            margin-top: 60px;
        }

        .logo_img img {
                width: 200px;
        }
        .weui_btn_primary1{
            position: absolute;
            right: 0;
        }
        input#get_mobile_code_btn{
            background: #04BE02;
            border: 0 none;
            padding: 4px 8px;
            color: #fff;
            font-size: 12px;
            border-radius: 4px;
        }
        .weui-yzm{
            position: relative;
        }
    </style>
</block>
<block name="body">


    <div class="weui_msg">
        <div class="weui_icon_area logo_img">
            <img src='__IMG__/logo-big.png' />
        </div>
        <div class="weui_text_area">
            <form action="{:U('UserRegister')}" method="post" id="_login_form" name="_login_form">

                <div class="weui_cells weui_cells_form">
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">手机号</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id='mobile' name='user_name' class="weui_input" type="tel" placeholder="请输入手机号码">
                        </div>
                    </div>

                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id='vcode' name='vcode' class="weui_input"  placeholder="请输入验证码">
                        </div>
                          <div class="weui_btn_primary1">  <img   src="{:C('WEBURL')}/captcha.php?1251847096"alt="captcha" onclick="this.src='{:C('WEBURL')}/captcha.php?'+Math.random()"  style="height:22px;top:0px;width:76px" class="captcha" title="看不清？刷新一下" /></div>
                      </div>
                    </div>
                                

                <div class="weui_cell weui-yzm">
                <div class="weui_cell_hd"><label class="weui_label">短信验证码</label></div>
                <div class="weui_cell_hd"><input type="text" maxlength="10" name="code" id="code" class="weui_input" placeholder="请获取短信验证码" /></div>
                <div class="weui_btn_primary1"><input type="button" value="获取验证码" id="get_mobile_code_btn" onclick="get_mobile_code(this)" /></div>
               </div>
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">登录密码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id='password' name='password' class="weui_input" type="password" placeholder="请输入登录密码">
                        </div>
                    </div> 
                    <div class="weui_cell">
                        <div class="weui_cell_hd"><label class="weui_label">确认密码</label></div>
                        <div class="weui_cell_bd weui_cell_primary">
                            <input id='password2' name='password2' class="weui_input" type="password" placeholder="请确认登录密码">
                        </div>
                    </div> 
                </div>

               

            </form>

        </div>
        <div class="weui_opr_area">
            <p class="weui_btn_area">
                <button id="_login_btn" class="weui_btn weui_btn_primary">确定注册</button>

                <a href="{:U('login')}" style=" width: 48%;" class="weui_btn weui_btn_mini weui_btn_primary">返回登录</a>
                <a href="{:C('WEBURL')}" style=" width: 48%;" class="weui_btn weui_btn_mini weui_btn_default">浏览首页</a>

            </p>
        </div>

    </div>

</block>
<!-- 脚本代码必须写在   block name="script" 标签里 -->
<block name="script">
    <!-- 引入JQ-WEUI插件【按需引入】 -->
    <script src="__THEMES__/js/jquery-weui.min.js?v={:C('CURRENT_FILE_VERSION')}"></script>
    <script type="text/javascript">
    var url_vcode = "{:C('WEBURL')}/user.php?act=act_register_aomaivip_check_yzm";
    var url_code = "{:U('UserRegister_code')}";
        $(function () {
            //给提交按钮绑定 touchend 时间。 如果用 click时间会有300-400毫秒的触发延时
            $("#_login_btn").on('touchend', function (e) {
                e.preventDefault();//阻止“默认行为”
                var _mobile=$.trim($('#mobile').val());
                if(_mobile=="")
                {
                    $.toast("请输入手机号码", "forbidden");
                    return;
                }

                var _code=$.trim($('#code').val());
                if(_code=="")
                {
                    $.toast("请输入验证码", "forbidden");
                    return;
                }
                var _password=$.trim($('#password').val());
                if(_password=="")
                {
                    $.toast("请输入登录密码", "forbidden");
                    return;
                }

                 var _password2=$.trim($('#password2').val());
                if(_password2=="")
                {
                    $.toast("请确认登录密码", "forbidden");
                    return;
                }

            
                if(_password2 !=_password)
                {
                    $.toast("2次密码输入不一致", "forbidden");
                    return;
                }

                var data = $('#_login_form').serialize();
                var url = $('#_login_form').attr('action');

                $.showLoading('注册中...');
                $.ajax({
                    url:url,
                    data:data,
                    type:'POST',
                    dataType:'json',
                    success: function (data) {
                        $.hideLoading();

                        if(data.status<1){
                            $.toast(data.message, "forbidden");
                            $('#_login_btn').html('注 册');
                            $('#_login_btn').removeAttr('disabled');
                        }else{
                            $.toast(data.message);
                            $('#_login_btn').html('51M登录成功,正在跳转...');
                            setTimeout(function(){
                                //window.location.href=data.url;
                                //window.location.href="{:C('WEBURL')}";
                                location.replace("{:C('WEBURL')}");
                            },900);
                            return;
                        }
                    },
                    error: function () {
                        $.hideLoading();
                        $.toast(data.message, "网络请求失败"); 
                        $('#_login_btn').html('注 册');
                        $('#_login_btn').removeAttr('disabled');
                    },complete:function(){
                       
                    }
                });

            });

        });
    function get_mobile_code(obj) {
        var _mobile=$.trim($('#mobile').val());
        var _vcode = $.trim($('#vcode').val())
        if(_mobile=="")
        {
            $.toast("请输入手机号码", "forbidden");
            return;
        }
        //var re = /^1[3|4|5|7|8]\d{9}$/;
        var re = /(^0\d{9}$)/;
        if (!re.test(_mobile))
        {
            $.toast("必须是澳洲的手机号码", "forbidden");
            return ;
        }
        if(_vcode=="")
        {
            $.toast("请输入验证码", "forbidden");
            return;
        }
         
         //验证验证码是否正确
          $.ajax({
            url: url_vcode,
            data: { aomai_vcode: _vcode, age:29 },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.status == 1) {
                           //验证码通过后在发送短信验证
                             $.ajax({
                                        url: url_code,
                                        data: { mobile: _mobile, mobile_code: "" },
                                        dataType: "json",
                                        type: "POST",
                                        success: function (result) {
                                            debugger;
                                            if (result.code == 1) {
                                               $.toast("验证码已成功发送到您的手机！");
                                                RemainTime();
                                            }else if(result.code == -2){
                                                $.toast(result.data, "forbidden");
                                            }else {
                                              $.toast(result.msg, "forbidden");
                                            }
                                        }, error: function () {


                                        }, complete: function () {

                                        }
                                    });
                }else {
                    $(".captcha").click();
                  $.toast(data.info, "forbidden");
                }
            }, error: function () {


            }, complete: function () {

            }
        });
         


    }


    var iTime = 59;
    var Account;
    function RemainTime() {
        document.getElementById('get_mobile_code_btn').disabled = true;
        var iSecond, sSecond = "", sTime = "";
        if (iTime >= 0) {
            iSecond = parseInt(iTime % 60);
            if (iSecond >= 0) {
                sSecond = iSecond + "s后可重发";
            }
            sTime = sSecond;
            if (iTime == 0) {
                clearTimeout(Account);
                sTime = '获取验证码';
                iTime = 59;
                document.getElementById('get_mobile_code_btn').disabled = false;
                $("#get_mobile_code_btn").removeClass("disabled");

            } else {
                Account = setTimeout("RemainTime()", 1000);
                iTime = iTime - 1;
            }
        } else {
            sTime = '没有倒计时';
        }
        document.getElementById('get_mobile_code_btn').value = sTime;
    }

    function dologin(obj) {
        window.location.href = "user.php?rcode={$register_recommended_code}";
    }
    </script>
</block>